package com.soilflow.web.controller.reception.web;

import com.soilflow.common.annotation.Log;
import com.soilflow.common.core.controller.BaseController;
import com.soilflow.common.core.domain.AjaxResult;
import com.soilflow.common.core.page.TableDataInfo;
import com.soilflow.common.domain.WechatMenu;
import com.soilflow.common.domain.vo.WechatMenuVo;
import com.soilflow.common.enums.BusinessType;
import com.soilflow.common.utils.poi.ExcelUtil;
import com.soilflow.info.service.IWechatMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 菜单Controller
 * 
 * @author party
 * @date 2023-09-26
 */
@RestController
@RequestMapping("/wechatDc/menu")

public class WechatMenuController extends BaseController {
    @Autowired
    private IWechatMenuService wechatMenuService;

    /**
     * 查询菜单列表
     */
    @PreAuthorize("@ss.hasPermi('system:menu:list')")
    @GetMapping("/list")
    public TableDataInfo list(WechatMenu wechatMenu) {
        startPage();
        List<WechatMenu> list = wechatMenuService.selectWechatMenuList(wechatMenu);
        return getDataTable(list);
    }
    /**
     * 查询菜单列表，并且包含子分类
     */
    @GetMapping("/findMenuInfo")
    public AjaxResult findMenuInfo(){
        List<WechatMenuVo> list = wechatMenuService.findMenuInfo();
        return AjaxResult.success(list);
    }
    /**
     * 同步菜单
     */
    @GetMapping("/syncMenu")
    public AjaxResult createMenu() {
        wechatMenuService.syncMenu();
        return AjaxResult.success();
    }

    /**
     * 导出菜单列表
     */
    @PreAuthorize("@ss.hasPermi('system:menu:export')")
    @Log(title = "菜单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WechatMenu wechatMenu)
    {
        List<WechatMenu> list = wechatMenuService.selectWechatMenuList(wechatMenu);
        ExcelUtil<WechatMenu> util = new ExcelUtil<WechatMenu>(WechatMenu.class);
        util.exportExcel(response, list, "菜单数据");
    }

    /**
     * 获取菜单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:menu:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(wechatMenuService.selectWechatMenuById(id));
    }

    /**
     * 新增菜单
     */
    @PreAuthorize("@ss.hasPermi('system:menu:add')")
    @Log(title = "菜单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WechatMenu wechatMenu)
    {
        return toAjax(wechatMenuService.insertWechatMenu(wechatMenu));
    }

    /**
     * 修改菜单
     */
    @PreAuthorize("@ss.hasPermi('system:menu:edit')")
    @Log(title = "菜单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WechatMenu wechatMenu)
    {
        return toAjax(wechatMenuService.updateWechatMenu(wechatMenu));
    }

    /**
     * 删除菜单
     */
    @PreAuthorize("@ss.hasPermi('system:menu:remove')")
    @Log(title = "菜单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wechatMenuService.deleteWechatMenuByIds(ids));
    }
}
